/*
 * Hidden Equity LLC
 * Author: Maksym Fedyay, Kyiv, mcsimf@gmail.com
 * Date: 29.02.2012
 */

package com.hiddenequity.utils;

import android.app.Application;
import android.content.SharedPreferences;

public class AppPreferences {
	
	
	
	/*
	 * Get Shared preferences
	 */
	private static SharedPreferences getAppSharedPreferences(Application application){
		SharedPreferences result = null;
		try {
			result =  application.getSharedPreferences("HEAdwords", 0);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			result = null;
		}
		
		return result;
	}//getAppSharedPreferences
	
	
	
	/*
	 * Save preferences Integer
	 */
	public static void SavePreferenceInt(String key, int value, Application application){
		SharedPreferences.Editor editor = getAppSharedPreferences(application).edit();
		editor.putInt(key, value);
		editor.commit();
	}//SavePreferencesInt
	
	
	
	/*
	 * Save preferences String
	 */
	public static void SavePreferenceStr(String key, String value, Application application){
		SharedPreferences.Editor editor = getAppSharedPreferences(application).edit();
		editor.putString(key, value);
		editor.commit();
	}//SavePreferencesStr
	
	
	/*
	 * Load String Preferences 
	 */
	public static String  LoadPreferenceStr(String key, Application application){
		String strAccountEmail = getAppSharedPreferences(application).getString(key, "");
		return strAccountEmail;
	}//LoadPreferencesStr
	
	
	
	/*
	 * Load String Preferences 
	 */
	public static int  LoadPreferenceInt(String key, int defaultValue, Application application){
		int strAccountEmail = 0;
		
		try {
			strAccountEmail = getAppSharedPreferences(application).getInt(key, defaultValue);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return strAccountEmail;
	}//LoadPreferencesInt
	
	
	
	/*
	 * Remove preference
	 */
	public static void RemovePreference(String key, Application application){
		SharedPreferences.Editor editor = getAppSharedPreferences(application).edit();
		editor.remove(key);
		editor.commit();
	}//RemovePreference
}
